<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/tags.jsp"%>
<aos:html>
<aos:head title="代理商信息列表">
	<aos:include lib="ext" />
	<aos:base href="console/chargedetail" />
</aos:head>
<aos:body>
</aos:body>
<aos:onready>
	<aos:viewport layout="border">
		<aos:formpanel id="qform" labelWidth="70" region="north"
			header="false" padding="5 0 0 0" border="false">

		</aos:formpanel>
		<aos:gridpanel id="grid" url="list" onrender="query"
			onitemdblclick="show_update" region="center">
			<aos:docked>
				 
			</aos:docked>
			<aos:selmodel type="checkbox" mode="multi" />
			<aos:column type="rowno" header="序号" width="40" />
			<aos:column header="id" dataIndex="id" width="40" />
			<aos:column header="代理商ID" dataIndex="agent_id" hidden="true" width="60" />
			<aos:column header="代理商名称" dataIndex="agent_name" width="60" />
			<aos:column header="交易金额" dataIndex="charge_money" width="100" />
			<aos:column header="余额" dataIndex="left_money" width="60" />
			<aos:column header="概述" dataIndex="remark" width="130" />
			<aos:column header="消费类型" dataIndex="charge_type" width="130" rendererFn="chargetype_ren" />
			<aos:column header="操作人 ID" dataIndex="operator_id" width="130" />
			<aos:column header="操作人 " dataIndex="operator_name" width="130" />
			<aos:column header="状态" dataIndex="state" width="60"
				rendererFn="state_ren" />
			<aos:column header="创建时间" dataIndex="creat_time" width="130" />
		</aos:gridpanel>

		<aos:window id="add_w" title="录入充值" maxHeight="-10" autoScroll="true">
			<aos:formpanel id="add_f" width="420" layout="anchor" labelWidth="80">
				<aos:combobox name="agent_id" fieldLabel="代理商名称" url="../findAgents"
					emptyText="－－请选择－－" allowBlank="false" />
				<aos:textfield name="charge_money" fieldLabel="充值金额 "
					allowBlank="false" />
				<aos:textareafield name="remark" fieldLabel="备注" allowBlank="true" />
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="add" text="保存" icon="ok.png" />
				<aos:dockeditem onclick="#add_w.hide();" text="关闭" icon="close.png" />
			</aos:docked>
		</aos:window>

		<aos:window id="deduct_w" title="扣款" maxHeight="-10" autoScroll="true">
			<aos:formpanel id="deduct_f" width="420" layout="anchor"
				labelWidth="80">
				<aos:combobox name="agent_id" fieldLabel="代理商名称" url="../findAgents"
					emptyText="－－请选择－－" allowBlank="false" />
				<aos:textfield name="charge_money" fieldLabel="扣款金额 "
					allowBlank="false" />
				<aos:textareafield name="remark" fieldLabel="备注" allowBlank="true" />
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="deduct" text="保存" icon="ok.png" />
				<aos:dockeditem onclick="#deduct_w.hide();" text="关闭"
					icon="close.png" />
			</aos:docked>
		</aos:window>

	</aos:viewport>

	<script type="text/javascript">
    
    function state_ren(v){
		if(v == 1){
			return '待审核'
		}else if(v == 2){
			return '审核通过'
		}else if(v == 3){
			return '审核不通过'
		}else{
			return v
		}
	}
    
    function chargetype_ren(v){
		if(v == 1){
			return '充值'
		}else if(v == 2){
			return '扣款'
		}else{
			return v
		}
	}
    
    
   	 
    function query(){
        grid_store.getProxy().extraParams = qform.getValues();
        grid_store.getProxy().getMethod = function(){ return 'POST'; }
        grid_store.load();
     }

	function show_add(){
		AOS.reset(add_f);
        add_w.show();
	}
	
	function show_deduct(){
		AOS.reset(deduct_f);
		deduct_w.show();
	}
	
	function add(){
		AOS.ajax({
            forms : add_f,
            url : 'add',
            ok : function(data) {
                	if(data.success){
                		 add_w.hide();
                     grid_store.reload();
                	}
                AOS.tip(data.appmsg);
            }
        }); 
	}
	
	
	
	function deduct(){
		AOS.ajax({
            forms : deduct_f,
            url : 'deduct',
            ok : function(data) {
                	if(data.success){
                		deduct_w.hide();
                     grid_store.reload();
                	}
                AOS.tip(data.appmsg);
            }
        }); 
	}
	
    function show_update(){
        AOS.reset(update_f);
        grid_store.reload();           
        var record = AOS.selectone(grid);
        grid.getSelectionModel().clearSelections();
        if(record){
            update_w.show();
            update_f.loadRecord(record);
        }
    }        
    
    function update(){
           AOS.ajax({
            forms : update_f,
            url : 'update',
            ok : function(data) {
                	if(data.success){
                		update_w.hide();
                    grid_store.reload();
                    grid.getSelectionModel().clearSelections()
                	}
                	AOS.tip(data.appmsg);
            }
        }); 
    }
    </script>
</aos:onready>
</aos:html>